package com.bnz.manager.service.impl;




import com.bnz.utils.PageUtils;

import com.bnz.utils.Query;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.bnz.manager.dao.BrandDao;
import com.bnz.manager.entity.BrandEntity;
import com.bnz.manager.service.BrandService;
import org.springframework.util.StringUtils;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    /**
     * 1. 条件查询带分页
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        System.out.println("params = " + params);
        //1.1 定义查询条件
        QueryWrapper<BrandEntity> queryWrapper = new QueryWrapper<>();
        //1.2 得到查询参数
        Object key = params.get("key");
        //1.3 封装查询参数
        if(!StringUtils.isEmpty(key.toString())){
             queryWrapper.like("name",key)
                            .or()
                            .like("first_char",key);
        }
        //1.4 开始条件查询带分页
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                queryWrapper
        );
        
        return new PageUtils(page);
    }

}